
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      
      <link rel="icon" href="../assets/images/favicon.png">
      <meta name="generator" content="mkdocs-1.1.2, mkdocs-material-7.1.3">
    
    
      
        <title>Nginx笔记 - py教程</title>
      
    
    
      <link rel="stylesheet" href="../assets/stylesheets/main.e35208c4.min.css">
      
        
        <link rel="stylesheet" href="../assets/stylesheets/palette.ef6f36e2.min.css">
        
      
    
    
    
      
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
        <style>:root{--md-text-font-family:"Roboto";--md-code-font-family:"Roboto Mono"}</style>
      
    
    
    
      <link rel="stylesheet" href="../extra.css">
    
    
      
    
    
  </head>
  
  
    
    
    
    
    
    <body dir="ltr" data-md-color-scheme="" data-md-color-primary="none" data-md-color-accent="none">
  
    
    <script>function __prefix(e){return new URL("..",location).pathname+"."+e}function __get(e,t=localStorage){return JSON.parse(t.getItem(__prefix(e)))}</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#nginx" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
      <header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href=".." title="py教程" class="md-header__button md-logo" aria-label="py教程" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            py教程
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              Nginx笔记
            
          </span>
        </div>
      </div>
    </div>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      
<div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
      </button>
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    


<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href=".." title="py教程" class="md-nav__button md-logo" aria-label="py教程" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>

    </a>
    py教程
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href=".." class="md-nav__link">
        首页
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2" type="checkbox" id="__nav_2" >
      
      <label class="md-nav__link" for="__nav_2">
        User Guide
        <span class="md-nav__icon md-icon"></span>
      </label>
      <nav class="md-nav" aria-label="User Guide" data-md-level="1">
        <label class="md-nav__title" for="__nav_2">
          <span class="md-nav__icon md-icon"></span>
          User Guide
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
  
  
  
    <li class="md-nav__item">
      <a href="../about/" class="md-nav__link">
        关于
      </a>
    </li>
  

          
            
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_2" type="checkbox" id="__nav_2_2" >
      
      <label class="md-nav__link" for="__nav_2_2">
        haha
        <span class="md-nav__icon md-icon"></span>
      </label>
      <nav class="md-nav" aria-label="haha" data-md-level="2">
        <label class="md-nav__title" for="__nav_2_2">
          <span class="md-nav__icon md-icon"></span>
          haha
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
  
  
  
    <li class="md-nav__item">
      <a href="../source/222/" class="md-nav__link">
        文件222
      </a>
    </li>
  

          
            
  
  
  
    <li class="md-nav__item">
      <a href="../source/333/" class="md-nav__link">
        文件333
      </a>
    </li>
  

          
        </ul>
      </nav>
    </li>
  

          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="https://www.baidu.com/" class="md-nav__link">
        有疑问?点我!
      </a>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    示例配置代码
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    汇总配置代码
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    配置与重载
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          <div class="md-content" data-md-component="content">
            <article class="md-content__inner md-typeset">
              
                
                
                <h1 id="nginx">Nginx笔记</h1>
<h2 id="_1">示例配置代码</h2>
<ul>
<li>单个静态H5项目部署</li>
</ul>
<pre><code>server {
  listen 80;
  charset utf-8;
  server_name 127.0.0.1;
  server_name  47.97.159.133;

   location / {
       root   /etc/nginx/sites-available;
       index  index.html index.htm;
   }
}
</code></pre>
<h2 id="_2">汇总配置代码</h2>
<blockquote>
<ul>
<li>同一域名, 不同路由</li>
<li>同一域名, 不同端口</li>
</ul>
</blockquote>
<pre><code class="language-shell"># 首页: uni前端, /mds: markdown文档
server {
  listen 80;
  charset utf-8;
  server_name 127.0.0.1;
  server_name  47.97.159.133;
  # rewrite ^/(.*) http://www.baidu.com/ permanent;    # 重定向

  # uni-app's client
  location / {
    root   /etc/nginx/sites-available;  # 注意此处root和后面alias的区别
    index  index.html index.htm;
  }

  # markdown documents
  location  /mds {
    alias  /etc/nginx/sites-available/mds/test_md_page.github.io;
    index  index.html index.htm;

    # proxy_pass   http://localhost:7080;    # 代理本地端口
  }
}



# uni后端
server {
  charset utf-8;
  listen 3389;
  server_name 47.97.159.133;  # 改成你的 IP

  location /static {
    alias /home/sites/uniapps/hello_uni/static;
  }

  location /media {
    alias /home/sites/uniapps/hello_uni/media;
  }

  location / {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8000;
  }
}

# my blog
server {
  # listen 80;
  listen 443;
  charset utf-8;
  server_name 127.0.0.1;
  server_name  47.97.159.133;

  location /static {
    alias /home/sites/bodexiong.vip/django_blog_tutorial/collected_static;
  }

  location /media {
    alias /home/sites/bodexiong.vip/django_blog_tutorial/media;
  }

  location / {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080;
  }
}
</code></pre>
<h2 id="_3">配置与重载</h2>
<p><a href="https://www.dusaiphoto.com/article/71/"><code>Django部署参考资料</code></a></p>
<ul>
<li>第一次运行时需要建立软连接, 将nginx的配置文件链接到<code>bdx.vip</code></li>
</ul>
<pre><code>sudo ln -sf /etc/nginx/sites-available/bdx.vip /etc/nginx/sites-enabled
</code></pre>
<ul>
<li>进入配置文件夹</li>
</ul>
<pre><code>cd /etc/nginx/sites-available
</code></pre>
<ul>
<li>打开文件, 然后将剪切板里的内容复制到文件中(<em>shift+insert</em>)</li>
</ul>
<pre><code># [ctrl+c]复制[汇总配置代码]

# 控制台输入
vim bdx.vip

# 按下[i], 进入编辑模式

# 按下[shift+insert]复制配置内容

# 按下[:], 输入[w]和[q], 保存并退出

# 重启nginx服务器
sudo service nginx reload
</code></pre>
<ul>
<li>
<p>其它</p>
</li>
<li>
<p>错误排查</p>
<p><em>如果重启nginx服务失败, 则运行<code>nginx -t</code>排查错误</em></p>
</li>
<li>
<p>配置改动</p>
<p>如果已有配置文件<code>bdx.vip</code>, 想要改动的话, 建议在本地改完然后<code>ctrl+c</code>复制, 服务器上直接<code>rm bdx.vip</code>删除然后<code>vim bdx.vip</code>重新<code>ctrl+v</code>输入配置, 这样操作感觉比vim进文件里面再删除全部内容来得快</p>
</li>
</ul>
<hr />
<h1 id="mkdocs">mkdocs文档网页更新</h1>
<blockquote>
<p>本地项目改动后, 想在服务器上也同步该怎么操作</p>
</blockquote>
<h2 id="_4">方案汇总</h2>
<ul>
<li>使用xftp上传</li>
<li>使用git/gitee作为中转站</li>
<li>托管到git静态网站(<em>gitee公告说个人静态网站功能要整改几个月, 暂时用不了</em>)</li>
</ul>
                
              
              
                


              
            </article>
          </div>
        </div>
        
      </main>
      
        
<footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-footer-copyright">
        
        Made with
        <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
          Material for MkDocs
        </a>
        
      </div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    <script id="__config" type="application/json">{"base": "..", "features": [], "translations": {"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}, "search": "../assets/javascripts/workers/search.fe42c31b.min.js", "version": null}</script>
    
    
      <script src="../assets/javascripts/bundle.4ea5477f.min.js"></script>
      
    
  </body>
</html>